import java.awt.*;
import javax.swing.*;

public class PhysicsLabApplet extends JApplet
{
    MyWorld world = new MyWorld();
   public void init()
   {
      //Title("Small Physics Laboratory");
      //setSize(MyWorld.WIDTH, MyWorld.HEIGHT+50);
      if(!getParameter("delta time").isEmpty())
      world.setDelta_t(Float.parseFloat(getParameter("delta time")));
      if(!getParameter("delta time").isEmpty())
      world.setRefreshPeriod(Float.parseFloat(getParameter("refresh time")));
      PhysicsLabPanel labPanel = new PhysicsLabPanel(world);
      PhysicsLabPanel labPanel2 = new PhysicsLabPanel(world);
      JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,
                           labPanel, labPanel2);
      splitPane.setOneTouchExpandable(false);
      splitPane.setDividerSize(1);
      splitPane.setDividerLocation(MyWorld.WIDTH);
      add(splitPane);  // it is equivalent to getContentPane().add(...);
      world.setPanel(labPanel);   // to repaint view when model changes
      ConfigurationMenuListener cListener = new ConfigurationMenuListener(world);
      WorldControlMenuListener wcListener = new WorldControlMenuListener(world);
      ActivateMenuListener amListener = new ActivateMenuListener();
      setJMenuBar(createLabMenuBar(cListener, wcListener,amListener));
   }
   
   public void SetParameters(String RefreshTime, String DeltaTime){
       if(!RefreshTime.isEmpty()){
       world.setDelta_t(Float.parseFloat(DeltaTime));}
       if(!DeltaTime.isEmpty()){
       world.setRefreshPeriod(Float.parseFloat(RefreshTime));}  
   }
 
   
      public JMenuBar createLabMenuBar(ConfigurationMenuListener cl,
              WorldControlMenuListener wl,ActivateMenuListener am) {
      JMenuBar mb = new JMenuBar();
      JMenu menu = new JMenu ("Configuration");
      am.get_menu(menu);
      mb.add(menu);
      JMenu subMenu = new JMenu("Insert");
      menu.add(subMenu);
      JMenuItem menuItem = new JMenuItem("Delete");
      menuItem.addActionListener(cl);
      menu.add(menuItem);
      menuItem = new JMenuItem("Set attribute...");
      menuItem.addActionListener(cl);
      menu.add(menuItem);

      menuItem = new JMenuItem("Ball");
      menuItem.addActionListener(cl);
      subMenu.add(menuItem);
      menuItem = new JMenuItem("Fixed Hook");
      menuItem.addActionListener(cl);
      subMenu.add(menuItem);
      menuItem = new JMenuItem("Rubber");
      menuItem.addActionListener(cl);
      subMenu.add(menuItem);
      menuItem = new JMenuItem("Spring");
      menuItem.addActionListener(cl);
      subMenu.add(menuItem);

      menu = new JMenu("MyWorld");
      mb.add(menu);
      menuItem = new JMenuItem("Start");
      menuItem.addActionListener(wl);
      menuItem.addActionListener(am);
      menu.add(menuItem);
      menuItem = new JMenuItem("Resume");
      menuItem.addActionListener(wl);
      menuItem.addActionListener(am);
      menu.add(menuItem);
      menuItem = new JMenuItem("Stop");
      menuItem.addActionListener(wl);
      menuItem.addActionListener(am);
      menu.add(menuItem);
      menuItem = new JMenuItem("Gravity");
      menuItem.addActionListener(wl);
      menu.add(menuItem);
      menuItem = new JMenuItem("Viscosity");
      menuItem.addActionListener(wl);
      menu.add(menuItem);
      subMenu = new JMenu("Simulator");
      menu.add(subMenu);
      menuItem = new JMenuItem("Delta time");
      menuItem.addActionListener(wl);
      subMenu.add(menuItem);
      menuItem = new JMenuItem("Graphics Refresh time");
      menuItem.addActionListener(wl);
      subMenu.add(menuItem);
      return mb;
   }
        
}
